package com.library.task;

import com.library.service.BorrowRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 定时任务
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class ScheduledTask {
    
    private final BorrowRecordService borrowRecordService;
    
    /**
     * 每天凌晨2点检查逾期记录
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void checkOverdueRecords() {
        log.info("开始检查逾期记录...");
        try {
            borrowRecordService.checkOverdueRecords();
            log.info("逾期记录检查完成");
        } catch (Exception e) {
            log.error("检查逾期记录失败", e);
        }
    }
}

